package com.kitty.game.rank.model.pojo;

import com.kitty.game.rank.model.RankData;
import com.kitty.game.rank.model.RankType;
import com.kitty.game.utils.JsonUtils;

import java.util.ArrayList;
import java.util.List;

/**排行数据，用于加载保存*/
public class RankGroupListData<T> extends RankData {
    private RankType rType;
    private List<DataUnit> rankData;

    public RankGroupListData() {}

    public RankGroupListData(RankType rankType, List<DataUnit> rankData) {
        this.rType = rankType;
        this.rankData = rankData;
    }

    public List<DataUnit> getRankData() {
        return this.rankData;
    }

    public void setRankData(List<DataUnit> rankData) {
        this.rankData = rankData;
    }

    public void doAfterInit(Class<T> clazz) {
        /**处理多层List<DataUnit<T>>的两层泛型，fastjson不支持多层泛型，不能直接使用new TypeReference<List<DataUnit<T>>>(clazz)*/
//        ParameterizedTypeImpl inner = new ParameterizedTypeImpl(new Type[]{clazz}, null, DataUnit.class);
//        ParameterizedTypeImpl outer = new ParameterizedTypeImpl(new Type[]{inner}, null, List.class);
        this.rankData = JsonUtils.string2Collection(data, ArrayList.class, DataUnit.class);
    }

    public void doBeforeSave() {
        if (rankData.size() > 0) {
            this.type = rType.name();
            this.data = JsonUtils.object2String(rankData);
        }
    }
}
